package com.ynny.Dao;

import com.ynny.Dao.optionai_coursesDao;
import com.ynny.Entity.optional_courses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class optional_coursesDao implements optionai_coursesDao {
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Override
    public int addCourse(String number, String courseName, Double score) {
        String sql = "insert into optional_courses(number,courseName,score) values(?,?,?)";
        return jdbcTemplate.update(sql,number,courseName,score);
    }

    @Override
    public List<optional_courses> queryCourseByNumber(String number) {
        String sql = "select * from optional_courses where number = ?";
        return jdbcTemplate.query(sql,new BeanPropertyRowMapper<>(optional_courses.class),number);
    }

    @Override
    public optional_courses CourseByNumber(String number) {
        String sql = "select * from optional_courses where number = ?";
        return jdbcTemplate.queryForObject(sql,new BeanPropertyRowMapper<>(optional_courses.class),number);
    }
}
